<link href="/IndexPublic/hb/css/style.css" type="text/css" rel="stylesheet">
<meta http-equiv="Access-Control-Allow-Origin" content="*">
<img class="hongbaoimg" src="/IndexPublic/images/linghongbao.png" style="display:none;" />
<div class="poplayer1">
    <div class="float-information">
        <div class="float-box get-packets">
            <div class="float-content">
                <div class="close-btn"><img src="/IndexPublic/hb/img/close-btn.jpg"></div>
                <div class="user-information" style="margin-top:13%;">
                    <div class="user-pic"><img src="{$eqinfo['p_logo']}"></div>
                    <em>{$eqinfo['p_name']}</em>
                </div>	
                <a class="get-btn" id="openhb"><img src="/IndexPublic/hb/img/btn.jpg"></a>
                <i>{$eqinfo['p_publicity']}</i>
            </div>
        </div>
        <div class="float-box lose-packets" style="display:none">
            <div class="float-content">
                <div class="close-btn"><img src="/IndexPublic/hb/img/close-btn.jpg"></div>
                <div class="user-information" style="width:100%; margin-top:13%;">
                    <div class="user-pic"><img src="{$eqinfo['p_logo']}"></div>
                    <em>{$eqinfo['p_name']}</em>
                    <span>您已领取过此红包</span>
                </div>
                <i>{$eqinfo['p_publicity']}</i>
            </div>
        </div>
    </div>
</div>
<style type="text/css">
.poplayer_tel{position:fixed; width:100%; height:100%; background-color:rgba(0,0,0,.6); z-index:110; top:0px;}
.poplayer_tel ul{width:70%; margin:0px auto; display:block; margin-top:150px;}
.poplayer_tel ul li{margin-bottom:10px; overflow:hidden; line-height:30px;}
.poplayer_tel ul li *{display:block; float:left;}
.poplayer_tel ul li input{border:solid 1px #CCC; height:30px; line-height:30px; width:100%; padding:0px 6px; border-radius:0px; background-color:#fff; font-size:14px;}
.poplayer_tel ul li input.userinput1{width:60%;}
.poplayer_tel ul li label{color:#fff; float:right; margin-right:3px; background-color:#CCC; color:#000; padding:0px 5px; margin-top:1px;}
.poplayer_tel ul li a.userinfook{display:block; width:100%; background-color:#dc0000; color:#fff; text-align:center; line-height:34px; font-size:16px; cursor:pointer;}
.poplayer_tel ul li a.userinfocanecl{text-align:center; display:block; clear:both; width:100%; line-height:24px; font-size:12px;}
</style>
<div class="poplayer_tel" style="display:none;">
	<ul>
		<li style="color: #fff; line-height: 20px; text-align: center; font-size: 12px;">您还没有手机验证，请填写相关信息，红包将自动发送到您的账户</li>
    	<li><input type="number" name="usertel" class="userinput1" placeholder="请输入手机号码" /><label id="jishi">获取验证码</label></li>
        <li><input type="number" name="userpass" class="userinput2" placeholder="请输入短信验证码" /></li>
        <li><a class="userinfook">确定</a></li>
        <li><a class="userinfocanecl">取消</a></li>
    </ul>
</div>
<div id="hbresult"></div>
<input type="hidden" name="openid" value="{$userinfo}" />
<input type="hidden" name="confirms" value="{$md5confirm}" />
<input type="hidden" name="urladdres" value="{$getURL}" />
<input type="hidden" name="appid" value="{$portinfo['u_appid']}" />
<input type="hidden" name="mchid" value="{$portinfo['u_merchantid']}" />
<input type="hidden" name="partnerkey" value="{$portinfo['u_paykey']}" />
<input type="hidden" name="clientcert" value="{$portinfo['u_cert']}" />
<input type="hidden" name="clientkey" value="{$portinfo['u_key']}" />
<script type="text/javascript">
$(document).ready(function($) {
	var getopenid = $("input[name='openid']").val();
	var confirms = $("input[name='confirms']").val();
	var appid = $("input[name='appid']").val();
	var mchid = $("input[name='mchid']").val();
	var partnerkey = $("input[name='partnerkey']").val();
	var clientcert = '{:C('WEBDOMAIN')}'+$("input[name='clientcert']").val();
	var clientkey = '{:C('WEBDOMAIN')}'+$("input[name='clientkey']").val();
	var rootid = '{$Think.get.rootid}';
	/*========================以上为获取相关信息=====================*/

	if($("input[name='openid']").val()==""){
		location.href="http://e.hrtv.cn/ehrtv/Login/index?url={$getURL}";
		return false;
	}
	var act_name = "华人频道红包计划";
	var send_name = "华人频道";
	var remark = "华人";
	var wishing = "华人";
	var getrandcode = "{$randcode}";
	/*验证手机*/
	$("a.userinfook").click(function(){
		var usertel = $("input[name='usertel']").val();
		var userpass = $("input[name='userpass']").val();
		if($.trim(usertel)==''){
			alert("请输入正确的手机号码！");
			return false;	
		}
		var vget_url = "/Home/Batch/getverifynote";
		var vdata = {"userpass":userpass,random:Math.random()};
		$.ajax({
			url:vget_url,
			data:vdata,
			type:"POST",
			dataType:"html",
			success:function (data){
				/*判断验证码是否正确*/
				if(data==1){
					/*手机验证通过保存数据*/
					var savetel_url = "/Home/Batch/savetelfalse";
					var teldata = {"usertel":usertel,"rootid":rootid,"useropenid":getopenid,random:Math.random()};
					$.ajax({
						url:savetel_url,
						data:teldata,
						type:"POST",
						dataType:"html",
						success:function (data){
							if(data==1){
								alert("您已领取过此红包！");
								pophidden();
								return false;
							}else if(data==-1){
								alert("注册失败，请重新输入信息！");
							}else if(data==0 || data=='ok'){
								//发送红包
								//alert(getopenid+"="+act_name+"="+send_name+"="+remark+"="+wishing+"="+confirms+"="+appid+"="+mchid+"="+partnerkey+"="+clientcert+"="+clientkey);
								insertdata(rootid,getopenid,act_name,send_name,remark,wishing,confirms,appid,mchid,partnerkey,clientcert,clientkey);
							}
						}
					});	
				}else{
					alert("验证不正确，请重新获取！");
					return false;	
				}

			}
		});	
	})

	$("#openhb").click(function(){
		var eckma_url = "/Home/Batch/checkhbmafasle";
		var eckdata = {"rootid":rootid,random:Math.random()};
		$.ajax({
			url:eckma_url,
			data:eckdata,
			type:"POST",
			dataType:"html",
			success:function (get_data){
				/*如果存在则执行以下程序*/
				if(get_data==1){
					var getdata_url = "/Home/Batch/getcishufalse";
					var data = {"rootid":rootid,"userinfo":getopenid,"random":Math.random()};
					$.ajax({
						url:getdata_url,
						data:data,
						type:"POST",
						dataType:"html",
						success:function (cishu_data){	//获取领取次数
							/*开始判断并执行*/
							if(cishu_data==1) {
								$(".get-packets").hide();
								$(".lose-packets").show();
								return false;
							}else if(cishu_data==0){
								insertdata(rootid,getopenid,act_name,send_name,remark,wishing,confirms,appid,mchid,partnerkey,clientcert,clientkey);
							}else if(cishu_data==-1){
								//如果没有则执行手机号注册
								$(".poplayer_tel").show();
							}
			
						}
					});	
				}else{
					alert("此码不存在红包活动！");
					pophidden();
					return false;
				}
			}
		});	

	})
	
	//插入数据库
	function insertdata(rootid,getopenid,act_name,send_name,remark,wishing,confirms,appid,mchid,partnerkey,clientcert,clientkey){
		if(getopenid!=''){
			var getdata_url = "http://pay.hrtv.cn/hongbao/sendredpack";
			var data = {"re_openid":getopenid,"act_name":act_name,"send_name":send_name,"remark":remark,"wishing":wishing,"confirm":confirms,"appid":appid,"mchid":mchid,"partnerkey":partnerkey,"clientcert":clientcert,"clientkey":clientkey};
			$.ajax({
				url:getdata_url,
				data:data,
				type:"GET",
				dataType:"JSON",
				success:function (val){
					if(val['statuss']==1){
						var status = val['statuss'];
						var total_amount = val['total_amount'];
						setrandstate(rootid,getopenid,status,total_amount);
					}else{
						if(val['info']=="系统错误:帐号余额不足，请到商户平台充值后再重试"){
							alert("红包活动已结束！");
							pophidden();
							return false;
						}
					}
				},
				error:function(val){
					alert('请求失败！');
				}
			});			
		}else{
			location.href="http://e.hrtv.cn/ehrtv/Login/index?url={$getURL}";	
		}	
	}
	
	//如果成功则设置该码的状态
	function setrandstate(rootid,openid,status,total_amount){
		var getdata_url = "/Home/Batch/setmastatefalse";
		var data = {"rootid":rootid,"openid":openid,"status":status};
		$.ajax({
			url:getdata_url,
			data:data,
			type:"POST",
			dataType:"html",
			success:function (data){
				if(data==1){
					alert('恭喜您获得'+total_amount/100+'元红包，请返回最近联系人界面查看红包到账消息');
					pophidden();
					return false;
				}else{
					alert("红包活动已结束！");
					pophidden();
					return false;
				}
			},
		});	
	}
	
	/*发送手机验证码*/
	$("#jishi").click(function(){
		var mobile = $("input[name='usertel']").val();
		var reg = /^0?1[3|4|5|8|7][0-9]\d{8}$/;
		if (!reg.test(mobile)) {
		   alert("请输入正确的手机号码！");
		   $("input[name='usertel']").val(null);
		   $("input[name='usertel']").focus();
		   return false;
    	}else{
			  var savetel_url = "/Home/Batch/savetel1";
			  var teldata = {"usertel":mobile,random:Math.random()};
			  $.ajax({
				  url:savetel_url,
				  data:teldata,
				  type:"POST",
				  dataType:"html",
				  success:function (data){
					  if(data==1){
						  alert("您已注册过，红包领取完毕！");
						  pophidden();
						  return false;
					  }else if(data=='no'){
							var send_url = "/Home/Batch/verifynote";
							var senddata = {"usertel":mobile,random:Math.random()};
							$.ajax({
								url:send_url,
								data:senddata,
								type:"POST",
								dataType:"html",
								success:function (data){
								}
							});	
							$("input[name='userpass']").focus();
							settime();
					  }else{
						  //alert(getopenid+"="+act_name+"="+send_name+"="+remark+"="+wishing+"="+confirms+"="+appid+"="+mchid+"="+partnerkey+"="+clientcert+"="+clientkey);
						  insertdata(getopenid,act_name,send_name,remark,wishing,confirms,appid,mchid,partnerkey,clientcert,clientkey);
					  }
				  }
			  });	
		}
			
	})
	
	//取消输入手机号则执行的操作
	function pophidden(){
		$(".poplayer_tel input").val(null);
		$(".poplayer_tel").hide();
		$(".poplayer1").hide();
		$("img.hongbaoimg").show();
	}
	//倒计时
	var countdown = 30; 
	function settime() { 
		if (countdown == 0) { 
			$("#jishi").html("获取验证码");
			countdown = 30; 
			return;
		} else { 
			$("#jishi").html("重新发送("+countdown+")"); 
			countdown--; 
		} 
		setTimeout(function() { 
			settime()
		},1000) 
	}
	
	$("a.userinfocanecl").click(function(){
		pophidden();	
	})
	$("div.poplayer_tel").click(function(){
		pophidden();
	})
	$("div.poplayer_tel ul").click(function(event){
		event.stopPropagation();
	})

	
	$(".float-box").click(function(event){
		event.stopPropagation();
	});
	$(".poplayer1").click(function(event){
		$(".float-box").hide();
		$(this).hide();
		$("img.hongbaoimg").show();
		event.stopPropagation();		
	});

	$(".pay-rule").click(function(){
		$(".poplayer1").show();
		$(".get-packets").show();		
	});

	$(".close-btn").click(function(){
		$(".poplayer1").hide();
		$(".explain").hide();
		$("img.hongbaoimg").show();	
	});
	$("img.hongbaoimg").click(function(){
		$(this).hide();
		$(".poplayer1").show();
		$(".get-packets").show();
	})

});	
</script>  